<?php
/**
 * Created by PhpStorm.
 * User: czm
 * Date: 2019-07-17
 * Time: 17:42
 */
namespace app\admin\controller;

use think\Controller;
use think\Db;

class Busines extends Controller
{
    // 商家管理
    public function businesList()
    {
        $list = Db::name('business')->select();
        $this->assign('data',$list);
        return $this->fetch();
    }

    public function businesEdit()
    {
        $id = $_POST['id'];
        $b = Db::name('business')->find($id);
        $this->assign('b',$b);
        if (request()->isPost()){
            $dat = input('post.');
            $r = Db::name('business')->where('id',input('id'))->update($dat);
            if ($r){
                return show(200);
            }else{
                return show(403);
            }

        }
        return $this->fetch();
    }

    // 审核或未审核
    public function businesActive()
    {
        // 0未审核状态  1已审核状态
        $id = $_POST['id'];
        $active = $_POST['state'];
        if($active == 0){
            db('business')->where('id',$id)->update(['state'=>0]);
            return show(200);
        }else if ($active == 1){
            db('business')->where('id',$id)->update(['state'=>1]);
            return show(403);
        }
    }

    public function businesShow()
    {
        $id = input('id');
//        var_dump($id);exit();
        $b = db('business')->find($id);
        $this->assign('b',$b);
        return $this->fetch();
    }

    public function businesDel()
    {
        $id = $_POST['id'];
        $data = Db::name('business')->where('id',$id)->delete($id);
        if($data){
            return show(200);
        }else{
            return show(403);
        }
    }
}